﻿using System;
using System.Web;
using OpenWaves;

namespace OpenWaves.Templates.Errors
{
    public class ErrorsHttpModule : IHttpModule
    {
        public void Dispose()
        {            
        }

        public void Init(HttpApplication context)
        {
            context.Error += OnError;
        }

        private void OnError(object sender, EventArgs eventArgs)
        {
            var exception = HttpContext.Current.Server.GetLastError();

            if (exception != null)
            {
                var httpException = exception as HttpException;
                if (httpException != null && httpException.GetHttpCode() == 404)
                    return;

                Log.Error(exception, "Unhandled exception has occured.");
            }
        }
    }
}